<template>
  <div class="wrapper" ref="wrapper">
    <div class="content">
      <slot></slot>
    </div>
  </div>
</template>

<script>
import BetterScroll from "better-scroll";
export default {
  data() {
    return {
      scroll: {},
    };
  },
  props: {
    probeType: {
      type: Number,
      default: 0,
    },
    pullUpLoad: {
      type: Boolean,
      default: false,
    },
  },
  mounted() {
    this.$nextTick(() => {
      //1. 创建bscroll对象
      this.scroll = new BetterScroll(this.$refs.wrapper, {
        click: true,
        observeDOM: true,
        probeType: this.probeType,
        pullUpLoad: this.pullUpLoad,
      });

      //2. 监听滚动位置
      if(this.probeType === 2 || this.probeType === 3){
				this.scroll.on("scroll", (position) => {
        this.$emit("scroll", position);
      });
			}

			//3. 监听上拉事件
			if(this.pullUpLoad){
				this.scroll.on("pullingUp", () => {
					this.$emit("pullingUp");
				});
			}
			// this.scroll.scrollHeight = 100000;
			// this.scroll.refresh()
    });
  },
  methods: {
    scrollTo(x, y, time = 5000) {
      this.scroll && this.scroll.scrollTo(x, y, time);
    },
    finishPullUp() {
      // setTimeout(() => {
      //   this.scroll.finishPullUp();
			// }, 2000);
			 this.scroll && this.scroll.finishPullUp();
		},
		refresh(){
			this.scroll && this.scroll.refresh();
    }
    // getScrollY(){

    // }
  },
};
</script>
<style scoped>
</style>